package com.zhuoyue.web.controller.system;

import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.core.domain.entity.SysThirdData;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.common.utils.SecurityUtils;
import com.zhuoyue.common.utils.poi.ExcelUtil;
import com.zhuoyue.system.service.ISysThirdDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Locale;
import java.util.UUID;


/**
 * @author zhanghui
 */
@RestController
@RequestMapping("/system/dict/thirdData")
public class SysThirdDataController extends BaseController {
    @Autowired
    private ISysThirdDataService sysThirdDataService;

    /**
     * 查询第三方数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysThirdData sysThirdData) {
        startPage();
        List<SysThirdData> list = sysThirdDataService.selectSysThirdDataList(sysThirdData);
        return getDataTable(list);
    }

    /**
     * 导出第三方数据
     */
    @GetMapping("/export")
    public AjaxResult export(SysThirdData sysThirdData) {
        List<SysThirdData> list = sysThirdDataService.selectSysThirdDataList(sysThirdData);
        ExcelUtil<SysThirdData> util = new ExcelUtil<>(SysThirdData.class);
        return util.exportExcel(list, "第三方数据");
    }


    /**
     * 新增第三方数据
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysThirdData sysThirdData) {
        sysThirdData.setId(UUID.randomUUID().toString().replace("-", "").toLowerCase(Locale.ROOT));
        sysThirdData.setCreateBy(SecurityUtils.getUsername());
        return toAjax(sysThirdDataService.insertSysThirdData(sysThirdData));
    }

    /**
     * 修改第三方数据
     */
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody SysThirdData sysThirdData) {
        sysThirdData.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(sysThirdDataService.updateSysThirdData(sysThirdData));
    }

    /**
     * 删除第三方数据
     */
    @DeleteMapping("/delete")
    public AjaxResult remove(String id) {
        return toAjax(sysThirdDataService.deleteSysThirdDataById(id));
    }
}
